home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / msdos / ctest259.zip / CACHES.PAS next >
Pascal/Delphi Source File  |  1992-04-07  |  3KB  |  84 lines

  1. {$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,R-,S-,V+,X-}
  2. {$M 4096,0,655360}
  3. UNIT Caches;
  4.  
  5. { Caches tries to determine the size of a first and a second level cache, if
  6.   either is present. This is done by having the external function TestCache
  7.   (or TestCache2 if the CPU is a 286 processor) perform block moves on the
  8.   the same memory block *twice*. Block size starts with 512 bytes and is doubled
  9.   in every iteration until block size is 512 kB. If the memory thruput drops
  10.   sharply after a increase in block size, it is safe to assume that the
  11.   previous block still fit into the cache, while the current block was to
  12.   large to fit into the cache. }
  13.  
  14. INTERFACE
  15.  
  16. PROCEDURE CacheSize (Debug, I386: BOOLEAN; VAR FirstLevel, SecondLevel: WORD;
  17.                      VAR CacheThru, Cache2Thru, MemThru: REAL);
  18.  
  19. IMPLEMENTATION
  20.  
  21. USES Crt;
  22.  
  23. TYPE CacheInfo    = ARRAY [1..10] OF WORD;
  24.      CacheInfoPtr = ^CacheInfo;
  25.  
  26. CONST ClockFreq = 1.193182e6;
  27.  
  28. FUNCTION TestCache:   CacheInfoPtr; FAR; EXTERNAL;
  29. FUNCTION TestCach286: CacheInfoPtr; FAR; EXTERNAL;
  30.  
  31. {$L CACHETST.OBJ}
  32.  
  33. PROCEDURE CacheSize (Debug, I386: BOOLEAN; VAR FirstLevel, SecondLevel: WORD;
  34.                      VAR CacheThru, Cache2Thru, MemThru: REAL);
  35.  
  36.  
  37.  
  38. VAR LongInfo: ARRAY [0..10] OF LONGINT;
  39.     Info: CacheInfoPtr;
  40.     NrValues, L, MemSize: WORD;
  41.  
  42. BEGIN
  43.    IF I386 THEN BEGIN
  44.       NrValues := 10;
  45.       Info := TestCache;
  46.       END
  47.    ELSE BEGIN
  48.       NrValues := 7;
  49.       Info := TestCach286;
  50.       END;
  51.    MemSize := 1;
  52.    FOR L := 1 TO NrValues DO BEGIN
  53.       LongInfo [L] := Info^[L];
  54.       WHILE (L <> 1) AND (LongInfo [L] < ((19 * LongInfo [L-1]) DIV 10)) DO
  55.          Inc (LongInfo [L], 65536);
  56.       IF Debug THEN
  57.          WriteLn ('CacheTest', L-1, ': ', LongInfo [L]:10 ,
  58.                    MemSize / (LongInfo [L] / ClockFreq):10:0 ,' kB/s');
  59.       MemSize := MemSize * 2;
  60.    END;
  61.    LongInfo [0]:= LongInfo [1];
  62.    FirstLevel  := 0;
  63.    SecondLevel := 0;
  64.    MemSize     := 1;
  65.    FOR L := 1 TO NrValues DO BEGIN
  66.       IF LongInfo [L] > ((22 * LongInfo [L-1]) DIV 10) THEN BEGIN
  67.          IF FirstLevel = 0 THEN BEGIN
  68.             CacheThru  := 0.5 * MemSize / (LongInfo [L-1] / ClockFreq);
  69.             FirstLevel := MemSize DIV 2
  70.             END
  71.          ELSE IF SecondLevel = 0 THEN BEGIN
  72.             Cache2Thru  := 0.5 * MemSize / (LongInfo [L-1] / ClockFreq);
  73.             SecondLevel := MemSize DIV 2;
  74.             END;
  75.          END;
  76.       IF L = NrValues THEN BEGIN
  77.          MemThru := 1.0 * MemSize / (LongInfo [L] / ClockFreq);
  78.          END;
  79.       Inc (MemSize, MemSize);
  80.    END;
  81. END;
  82.  
  83. END.
  84.